package com.example.demo.service;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.example.demo.dao.HistoryMapper;
import com.example.demo.model.History;
import com.example.demo.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * 功能描述：
 *更新用户阅读记录
 * @Author: Zhanghf
 * @Date: 2021/6/22 17:35
 */
@Service
public class HistoryService {

    @Autowired(required = false)
    private HistoryMapper historyMapper;
    @Async
    public void AysncUpdate(User user, Integer bookid, Integer chapterid)
    {
        if (user!=null)
    {
        int update = historyMapper.update(null,new UpdateWrapper<History>().eq("userid",user.getId()).eq("bookid",bookid).set("chapterid",chapterid).set("date",new Date()));
        if (update!=1)
        {
            historyMapper.insert(new History(user.getId(),bookid,chapterid,new Date()));
        }
    }
    }
}
